import * as THREE from '../../../../modules/three/three.module.js'
import {WorldConfig} from "../CommonConsts.js";
import DroneMesh from "./DroneMesh.js";

// 无人机喷涂动画展示时，使用的网格对象
export default class SprayPerformer extends THREE.Group {

  _lineSegments
  _drone

  constructor() {
    super()

    // const ballGeo = new THREE.SphereGeometry(radius, 8, 6)
    // const ballMat = new THREE.MeshLambertMaterial({color: '#fff', wireframe: true})
    // const ballMesh = new THREE.Mesh(ballGeo, ballMat)
    const len = WorldConfig.spray_to_plane_distance + WorldConfig.building_plane_distance
    const lineAttrPos = new THREE.BufferAttribute(new Float32Array([0,0,0, 0,0,-len]), 3)
    const lineGeo = new THREE.BufferGeometry()
    lineGeo.setAttribute('position', lineAttrPos)
    const lineSegments = new THREE.LineSegments(lineGeo, new THREE.LineBasicMaterial( { color: '#a20a24', toneMapped: false } ))

    // this.add(ballMesh)
    this.add(lineSegments)
    this._lineSegments = lineSegments

    const droneMesh = new DroneMesh()
    this._drone = droneMesh
    droneMesh.init()
    this.add(droneMesh)
  }

  setSprayColor(cssColorStr) {
    this._lineSegments.material.color.setStyle(cssColorStr)
  }

  toggleLine(visible) {
    this._lineSegments.visible = visible
  }

  // 旋转无人机旋翼
  animateDronePaddle() {
    this._drone.rotatePaddle()
  }
}
